package com.leokok.jts.learning.jts.core.algorithm.locator;

import org.junit.Test;
import org.locationtech.jts.algorithm.locate.IndexedPointInAreaLocator;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

/**
 * 判断点在areal geometry的相对位置
 * 支持 Polygonal and LinearRing
 */
public class IndexedPointInAreaLocatorTest {


    @Test
    public void locateTest() throws ParseException {
        WKTReader wktReader = new WKTReader();
        Geometry polygon = wktReader.read("POLYGON ((115.875 40.003, 115.863 39.988, 115.86166666666666 39.987, 115.865 39.964, 115.908 39.963, 115.918 39.985, 115.919 40.006, 115.875 40.003))");

        Geometry point01 = wktReader.read("POINT (116 40)");
        Geometry point02 = wktReader.read("POINT (115.891 39.983)");

        IndexedPointInAreaLocator indexedPointInAreaLocator = new IndexedPointInAreaLocator(polygon);
        //在边上=1  内部=0 外部=2
        System.out.println("p1:"+indexedPointInAreaLocator.locate(point01.getCoordinate()));
        System.out.println("p2:"+indexedPointInAreaLocator.locate(point02.getCoordinate()));

        //p1:2
        //p2:0
    }
}
